package com.cy.cdas.dao;


import com.cy.cdas.entity.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UserDao {



    @Insert("INSERT INTO user (name,gender,phone,birthday,account,password,isAdmin,email,headImg)VALUES " +
            "(#{name},#{gender},#{phone},#{birthday},#{account},#{password},#{isAdmin},#{email},#{headImg})"
    )
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")//useGeneratedKeys = true返回插入后生成的主键值，
    int add(User user);


//    @Delete("DELETE FROM user WHERE id IN (#{arg0})")
    @Delete({
            "<script>",
            "DELETE FROM user WHERE id IN",
            "<foreach item='item' index='index' collection='arg0'",
            "open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"
    })
    int delete(List<Integer> ids);

    @Update("UPDATE user SET " +
            "name=#{name}," +
            "gender=#{gender}," +
            "phone=#{phone}," +
            "birthday=#{birthday}," +
            "account=#{account}," +
            "password=#{password}," +
            "isAdmin=#{isAdmin}," +
            "email=#{email}," +
            "headImg=#{headImg} WHERE id = #{id}")
    int update(User user);

    @Select("SELECT * FROM user")
    List<User> getAllUsers();

    @Select("SELECT * FROM user WHERE id=#{id}")
    List<User> getOne(int id);
}
